home *** CD-ROM | disk | FTP | other *** search
/ PC Answers 1998 January / PC Answers Issue 49 Cover CD January 1998.iso / Apps / Director / DATA.Z / Widget Wizard.dir / Internal_41_Primary Movie Script.ls < prev    next >
Encoding:
Text File  |  1997-05-10  |  10.1 KB  |  280 lines

  1. global gArtSprite, gAltParamList, gExportList, gInstructStart, gInstructionsList, gInstructions, gPasteList, gInstructionWindow, gFirstWindowFlag, gInstructRect, gInstructStep, gInstructTotal, gWizWindow, gButtonName, LocationList, gCurrentSprite, PasteInfoList, gSpriteCount, gSpritePhrase, gUserSelection, gFrameCountMin, gFrameCountMax, gStartFrame, gStartSprite, gExportScriptList
  2.  
  3. on startMovie
  4.   set gArtSprite to 24
  5.   set gFirstWindowFlag to 0
  6.   set gWizWindow to the movieName
  7.   set gExportScriptList to []
  8.   go(1)
  9. end
  10.  
  11. on stopMovie
  12.   cursor(-1)
  13.   forgetInstructions()
  14.   if objectp(window gWizWindow) then
  15.     forget(window gWizWindow)
  16.   end if
  17. end
  18.  
  19. on closeWindow
  20.   set myName to the movieName
  21.   set offS to offset(".dir", myName)
  22.   if offS then
  23.     delete char offS to offS + 4 of myName
  24.   end if
  25.   forget(window myName)
  26. end
  27.  
  28. on validateUserSelection
  29.   set gCurrentSprite to 24
  30.   set gFrameCountMin to 5
  31.   set gFrameCountMax to 15
  32.   set mySprite to gCurrentSprite
  33.   set myFlag to 1
  34.   set gSpriteCount to 0
  35.   repeat while myFlag = 1
  36.     if the type of sprite mySprite = 0 then
  37.       if the type of sprite (mySprite + 1) = 0 then
  38.         set myFlag to 0
  39.         exit repeat
  40.       else
  41.         set gSpriteCount to gSpriteCount + 1
  42.         set mySprite to mySprite + 1
  43.       end if
  44.       next repeat
  45.     end if
  46.     set gSpriteCount to gSpriteCount + 1
  47.     set mySprite to mySprite + 1
  48.   end repeat
  49.   if gSpriteCount = 1 then
  50.     set gSpritePhrase to "channel"
  51.   else
  52.     set gSpritePhrase to "channels"
  53.   end if
  54.   tell the stage
  55.     set gUserSelection to the scoreSelection
  56.   end tell
  57.   if gUserSelection = [] then
  58.     alert("Please click in the score where you want the widget to begin, then try again.  You need " && gSpriteCount && "sprite" && gSpritePhrase && "and at least" && gFrameCountMin && "frames. ")
  59.     abort()
  60.   end if
  61.   set gStartSprite to getAt(getAt(gUserSelection, 1), 1)
  62.   set myEndSprite to gStartSprite + gSpriteCount - 1
  63.   set gStartFrame to getAt(getAt(gUserSelection, 1), 3)
  64.   set myEndFrame to gStartFrame + gFrameCountMax - 1
  65.   if gStartSprite < 1 then
  66.     alert("Your selection must start in sprite channel 1 or greater.  Please make a new selection and try again.")
  67.     abort()
  68.   end if
  69.   tell the stage
  70.     repeat with y = gStartFrame to myEndFrame
  71.       set myFrameCounter to y - gStartFrame
  72.       go(y)
  73.       repeat with z = gStartSprite to myEndSprite
  74.         if the type of sprite z <> 0 then
  75.           if myFrameCounter < gFrameCountMin then
  76.             alert("This selection contains something already.  You need " && gSpriteCount && "sprite" && gSpritePhrase && "and at least" && gFrameCountMin && "frames.  Please click in the score where you want the widget to begin, then try again.")
  77.             abort()
  78.             next repeat
  79.           end if
  80.           set gFrameCountMax to myFrameCounter
  81.           set myEndFrame to myFrameCounter - 1
  82.           exit repeat
  83.         end if
  84.       end repeat
  85.     end repeat
  86.     go(gStartFrame)
  87.   end tell
  88.   copyButtonPrime()
  89. end
  90.  
  91. on copyButtonPrime
  92.   cursor(4)
  93.   go(the frame + 1)
  94.   go(the frame - 1)
  95.   set myMemberNum to 1
  96.   set PasteInfoList to []
  97.   set mySpriteList to []
  98.   set myWidgetScriptList to []
  99.   set myAssocPasteList to []
  100.   repeat with x = gCurrentSprite to gCurrentSprite + gSpriteCount - 1
  101.     set myRecord to [#MemberName: EMPTY, #MemberNumber: 0, #ScriptName: EMPTY, #ScriptNumber: 0, #MemberLoc: point(0, 0), #MemberRect: rect(0, 0, 0, 0), #Onstage: 0]
  102.     if the type of sprite x <> 0 then
  103.       set the MemberName of myRecord to the name of member the member of sprite x
  104.       set the MemberLoc of myRecord to the loc of sprite x
  105.       set the MemberRect of myRecord to the rect of sprite x
  106.       copyToClipBoard(member the member of sprite x)
  107.       tell the stage
  108.         repeat while the type of member myMemberNum of castLib 1 <> #empty
  109.           set myMemberNum to myMemberNum + 1
  110.         end repeat
  111.         pasteClipBoardInto(member myMemberNum of castLib 1)
  112.         set the MemberNumber of myRecord to the number of member myMemberNum of castLib 1
  113.       end tell
  114.       if the scriptNum of sprite x > 0 then
  115.         set myAssocList to []
  116.         set myAssocList to getAssocMembers(getAt(the scriptInstanceList of sprite x, 1))
  117.         set myAssocPasteIndex to 0
  118.         repeat with r = 1 to count(myAssocPasteList)
  119.           if myAssocList = getAt(myAssocPasteList, r) then
  120.             set myAssocPasteIndex to r
  121.           end if
  122.         end repeat
  123.         if myAssocPasteIndex = 0 then
  124.           repeat with a = 1 to count(myAssocList)
  125.             copyToClipBoard(member getAt(myAssocList, a))
  126.             tell the stage
  127.               repeat while the type of member myMemberNum of castLib 1 <> #empty
  128.                 set myMemberNum to myMemberNum + 1
  129.               end repeat
  130.               pasteClipBoardInto(member myMemberNum of castLib 1)
  131.             end tell
  132.           end repeat
  133.           add(myAssocPasteList, myAssocList)
  134.         end if
  135.         set myScriptName to the name of member the scriptNum of sprite x
  136.         set the ScriptName of myRecord to myScriptName
  137.         set myWidgetScriptIndex to 0
  138.         repeat with q = 1 to count(myWidgetScriptList)
  139.           if the ScriptName of getAt(myWidgetScriptList, q) = myScriptName then
  140.             set myWidgetScriptIndex to q
  141.           end if
  142.         end repeat
  143.         if myWidgetScriptIndex = 0 then
  144.           copyToClipBoard(member the scriptNum of sprite x)
  145.           set myWidgetScriptRecord to [#ScriptName: EMPTY, #ScriptNumber: 0]
  146.           set the ScriptName of myWidgetScriptRecord to myScriptName
  147.           tell the stage
  148.             repeat while the type of member myMemberNum of castLib 1 <> #empty
  149.               set myMemberNum to myMemberNum + 1
  150.             end repeat
  151.             pasteClipBoardInto(member myMemberNum of castLib 1)
  152.             set myScriptNumber to the number of member myMemberNum of castLib 1
  153.             set the ScriptNumber of myRecord to myScriptNumber
  154.             set the ScriptNumber of myWidgetScriptRecord to myScriptNumber
  155.           end tell
  156.           add(myWidgetScriptList, myWidgetScriptRecord)
  157.         else
  158.           set the ScriptNumber of myRecord to the ScriptNumber of getAt(myWidgetScriptList, myWidgetScriptIndex)
  159.         end if
  160.       end if
  161.     end if
  162.     add(PasteInfoList, myRecord)
  163.   end repeat
  164.   set myFrameScriptName to "loop current frame"
  165.   copyToClipBoard(member myFrameScriptName)
  166.   tell the stage
  167.     repeat while the type of member myMemberNum of castLib 1 <> #empty
  168.       set myMemberNum to myMemberNum + 1
  169.     end repeat
  170.     pasteClipBoardInto(member myMemberNum of castLib 1)
  171.     set myFrameScriptNum to the number of member myMemberNum of castLib 1
  172.     set myScriptRecord to [#ScriptName: myFrameScriptName, #ScriptNumber: myFrameScriptNum]
  173.     add(gExportScriptList, myScriptRecord)
  174.   end tell
  175.   set myTestRect to rect(1, 1, 496, 342)
  176.   set myPlacementFlag to 0
  177.   repeat with s = 1 to count(PasteInfoList)
  178.     set myCurrentRect to the MemberRect of getAt(PasteInfoList, s)
  179.     if union(myTestRect, myCurrentRect) = myTestRect then
  180.       if myPlacementFlag = 0 then
  181.         set myPlacementFlag to 1
  182.         set myBoundingRect to myCurrentRect
  183.       else
  184.         set myBoundingRect to union(myBoundingRect, myCurrentRect)
  185.       end if
  186.       set the Onstage of getAt(PasteInfoList, s) to 1
  187.     end if
  188.   end repeat
  189.   set myBoundingWidth to getAt(myBoundingRect, 3) - getAt(myBoundingRect, 1)
  190.   set myBoundingHeight to getAt(myBoundingRect, 4) - getAt(myBoundingRect, 2)
  191.   tell the stage
  192.     set myStageWidth to the stageRight - the stageLeft
  193.     set myStageHeight to the stageBottom - the stageTop
  194.   end tell
  195.   set myStartH to (myStageWidth - myBoundingWidth) / 2
  196.   set myStartV to (myStageHeight - myBoundingHeight) / 2
  197.   set myBoundingH to getAt(myBoundingRect, 1)
  198.   set myBoundingV to getAt(myBoundingRect, 2)
  199.   tell the stage
  200.     beginRecording()
  201.     repeat with y = gStartFrame to gStartFrame + gFrameCountMax - 1
  202.       set myListCount to 1
  203.       go(y)
  204.       if the frame = (gStartFrame + gFrameCountMax - 1) then
  205.         set the frameScript to myFrameScriptNum
  206.       end if
  207.       repeat with z = gStartSprite to gStartSprite + gSpriteCount - 1
  208.         set myRecord to getAt(PasteInfoList, myListCount)
  209.         set myListCount to myListCount + 1
  210.         if the MemberNumber of myRecord > 0 then
  211.           set the member of sprite z to the MemberNumber of myRecord
  212.           if the Onstage of myRecord = 0 then
  213.             set the loc of sprite z to the MemberLoc of myRecord
  214.           else
  215.             set myMemberH to getAt(the MemberLoc of myRecord, 1)
  216.             set myMemberV to getAt(the MemberLoc of myRecord, 2)
  217.             set myPasteHdif to myMemberH - myBoundingH
  218.             set myPasteVdif to myMemberV - myBoundingV
  219.             set the loc of sprite z to point(myStartH + myPasteHdif, myStartV + myPasteVdif)
  220.           end if
  221.           if the ScriptNumber of myRecord <> 0 then
  222.             set the scriptNum of sprite z to member the ScriptNumber of myRecord
  223.           end if
  224.           set the tweened of sprite z to 1
  225.         end if
  226.       end repeat
  227.     end repeat
  228.     endRecording()
  229.   end tell
  230.   beep(2)
  231.   cursor(-1)
  232.   openInstructionWindow()
  233. end
  234.  
  235. on setWindowRect
  236.   if gFirstWindowFlag = 0 then
  237.     set myLeft to the stageLeft + 50
  238.     set myTop to the stageTop + 50
  239.     set myWidth to 160
  240.     set myHeight to 400
  241.     set gInstructRect to rect(myLeft, myTop, myLeft + myWidth, myTop + myHeight)
  242.     set gFirstWindowFlag to 1
  243.   end if
  244. end
  245.  
  246. on openInstructionWindow
  247.   if objectp(gInstructionWindow) then
  248.     forgetInstructions()
  249.   end if
  250.   setWindowRect()
  251.   set gInstructionWindow to window "Instructions"
  252.   set the rect of gInstructionWindow to gInstructRect
  253.   set the fileName of gInstructionWindow to the pathName & "-Instrct.dir"
  254.   set the titleVisible of gInstructionWindow to 0
  255.   set the windowType of gInstructionWindow to 49
  256.   open(gInstructionWindow)
  257.   resetInstructText()
  258. end
  259.  
  260. on resetInstructText
  261.   tell gInstructionWindow
  262.     displayNewText()
  263.   end tell
  264. end
  265.  
  266. on forgetInstructions
  267.   if objectp(gInstructionWindow) then
  268.     set gFirstWindowFlag to 1
  269.     set gInstructRect to the rect of gInstructionWindow
  270.     forget(gInstructionWindow)
  271.   end if
  272. end
  273.  
  274. on initElements
  275.   set gInstructStart to the frameLabel & "-1"
  276.   if objectp(gInstructionWindow) then
  277.     resetInstructText()
  278.   end if
  279. end
  280.